import Vue from 'vue'
import VueRouter from 'vue-router'
const Index=() => import('../views/index.vue');
const BackStage=() => import('../views/back-stage.vue');
const Register=() => import('../views/register.vue');
const Upload=() => import('../views/upload.vue')

Vue.use(VueRouter)

const routes = [
    {
        meta: {
            title: '主页'
        },
        path: '/',
        name: 'index',
        component: Index,
    },
    {
        meta: {
            title: '后台'
        },
        path: '/back-stage',
        name: 'back-stage',
        component: BackStage
    },
    {
        meta: {
            title: '浏览器认证'
        },
        path: '/register',
        name: 'register',
        component: Register
    },
    {
        meta: {
            title: '上传页面'
        },
        path: '/upload',
        name: 'upload',
        component: Upload
    }
]

const router = new VueRouter({
    mode: 'hash',
    routes
})

router.beforeEach((to, from, next) => {
    // 路由全局守卫
    if(to.meta.title) {
        document.title = to.meta.title
    }
    next()
})

export default router